package acwing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class lc1827 {
    static int[] nums = new int[5000];
    static int n;
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    static int count = 0;
    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(in.readLine());
        String[] str = in.readLine().split(" ");
        for(int i = 0; i < n; i ++ ){
            nums[i] = Integer.parseInt(str[i]);
        }
        for(int i = 1; i < n; i ++ ){
//            count += Math.abs(nums[i] - nums[i - 1]);
            if(nums[i] == nums[i - 1]){
                count ++;
                nums[i] ++;
            }else if(nums[i] < nums[i - 1]){
                count += nums[i - 1] - nums[i] + 1;
                nums[i] = nums[i - 1] + 1;
            }
        }
        out.println(count);
        out.close();
    }
}
